﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using EFFC.Net.Log;
using EFFC.Net.Resource;
using System.Collections.Generic;
using EFFC.Net.Parameters;
using EFFC.Net.WebBuilder.Public;

namespace EFFC.Net.WebBuilder.WebParameters
{
    /// <summary>
    /// SHS的操作记录参数定义
    /// </summary>
    public class WebOperatorP : OperatorParameters
    {
        public WebOperatorP()
        {
            AddPElement("AgentID");
            AddPElement("FunctionID");
            AddPElement("ActionID");
            AddPElement("UseItem");
            AddPElement("SQL");
        }
        /// <summary>
        /// 代理人ID
        /// </summary>
        public string AgentID
        {
            get { return GetValue<string>("AgentID"); }
            set { SetValue("AgentID", value); }
        }
        /// <summary>
        /// 代理人ID
        /// </summary>
        public string FunctionID
        {
            get { return GetValue<string>("FunctionID"); }
            set { SetValue("FunctionID", value); }
        }
        /// <summary>
        /// ActionID
        /// </summary>
        public string ActionID
        {
            get { return GetValue<string>("ActionID"); }
            set { SetValue("ActionID", value); }
        }
        /// <summary>
        /// UseItem
        /// </summary>
        public string UseItem
        {
            get { return GetValue<string>("UseItem"); }
            set { SetValue("UseItem", value); }
        }
        /// <summary>
        /// SQL
        /// </summary>
        public string SQL
        {
            get { return GetValue<string>("SQL"); }
            set { SetValue("SQL", value); }
        }
    }
    public class SHSLogOperator:DefaultLogOperator
    {
        public override void WriteOperator(OperatorParameters p)
        {
            ADBAccess dao = ResouceManager.CreateInstance<SQLServerAccess>();
            dao.Open(WebConfigString.DBConn);
            DBAP dbp = ADBAccess.GetDBParametersDefine();
            string sql = "INSERT INTO OperateHistory(ID,OprDateTime,UserID,AgentID,FunctionID,ActionID,UseItem,SQL)VALUES('" + Guid.NewGuid() + "',GETDATE(),@UserID,@AgentID,@FunctionID,@ActionID,@UseItem,@SQL)";
            DBOParameterCollection dbopc = new DBOParameterCollection();
            dbopc.Add("UserID", p.User);
            dbopc.Add("AgentID", p.GetValue<string>("AgentID"));
            dbopc.Add("FunctionID", p.GetValue<string>("FunctionID"));
            dbopc.Add("ActionID", p.GetValue<string>("ActionID"));
            dbopc.Add("UseItem", p.GetValue<string>("UseItem"));
            dbopc.Add("SQL", p.GetValue<string>("SQL"));
            dbp.SQL = sql;
            dbp.SQL_Parameters = dbopc;
            dao.ExecuteNoQuery(dbp);
            dao.Close();
        }
    }
}
